package com.heima.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heima.common.PageResult;
import com.heima.pojo.Partner;
import com.heima.mapper.PartnerMapper;
import com.heima.pojo.vo.PartnerVo;
import com.heima.service.IPartnerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 合作商表 服务实现类
 *
 * @author xjy
 * @since 2024-06-04
 */
@Service
public class PartnerServiceImpl extends ServiceImpl<PartnerMapper, Partner> implements IPartnerService {
    @Autowired
    private PartnerMapper tbPartnerMapper;

    /**
     * 分页查询合作商列表
     * @param name 名字
     * @return
     */
    @Override
    public PageResult<PartnerVo> search(PageResult<PartnerVo> pageResult, String name) {
        Page page = new Page<>(pageResult.getPageIndex(), pageResult.getPageSize());
        tbPartnerMapper.search(page, name);
        return pageResult.of(page, PartnerVo.class);
    }

    /**
     * 根据id查询合作商
     * @param id 合作商id
     * @return
     */
    @Override
    public PartnerVo getPartnerById(Long id) {
        return tbPartnerMapper.getById(id);
    }
}
